<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script id="tpl" type="text/html">
      <div>
        <h1>我是公共的头部组件</h1>  
          <h2>我是副标题</h2>
          <button @click="change">改变数据</button>
          {{ msg }}
          {{ msg2 }}
        </div>
  </script>
  <script src="./vue.js"></script>
  <script>

    // 定义一个 头部组件
    const CommonHead = {
      template:"#tpl",
      data () {
        return {
          msg: '我是组件中的数据'
        }
      },
      methods: {
        change () {
          this.msg = "数据改变啦"
        }
      },
      watch: {
        msg (newVal) {
          console.log(newVal)
        }
      },
      computed: {
        msg2 () {
          return this.msg.split('').reverse().join('')
        }
      }
    }
    // 挂载到全局上
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>